<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="button" value="毫无用处的按钮">
		<input type="button" value="绑定click">
		<input type="button" value="解除绑定">
		
		<script type="text/javascript">
			// 封装
			var EventUtil = {
				addHandler: function(oElement, sEvent, fnHandler) {
					oElement.addEventListener ? oElement.addEventListener(sEvent, fnHandler, false) : oElement.attachEvent("on"+sEvent, fnHandler)
				},
				removeHandler: function (oElement, sEvent, fnHandler) {
					oElement.removeEventListener ? oElement.removeEventListener(sEvent, fnHandler, false) : oElement.detachEvent("on" + sEvent, fnHandler)
				},
				// 给window的load事件添加函数，其实相当于window.onload = function(){} ?
				addLoadHandler: function (fnHandler) {
					this.addHandler(window, "load", fnHandler)
				}
			}
			// 绑定
			EventUtil.addLoadHandler(function(){
				var input = document.getElementsByTagName("input");
				EventUtil.addHandler(input[1],"click",function(){
					EventUtil.addHandler(input[0],"click",fnHandler);
					input[0].value="我可以点击了";
				});
			
				EventUtil.addHandler(input[2],"click",function(){
					EventUtil.removeHandler(input[0],"click",fnHandler);
					input[0].value="毫无用处的按钮";
				});
			
				function fnHandler() {
					alert("事件绑定成功！");
				}
			});
			
		</script>
	</body>
</html>
